﻿<UserControl x:Class="InkCanvasControls.InkCanvasControls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:self="clr-namespace:InkCanvasControls"
    Height="Auto" Width="Auto">

    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="boolToVis"/>
        <self:ProportionOfWidthValueConverter x:Key="ProportionOfWidth"/>
            <Style x:Key="DisabledButton" TargetType="{x:Type Button}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" Value="0.25"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static self:InkCanvasControls.PenCommand}" CanExecute="ToolCommandCanExecute" Executed="PenCommandExecuted"/>
        <CommandBinding Command="{x:Static self:InkCanvasControls.StrokeEraserCommand}" CanExecute="ToolCommandCanExecute" Executed="StrokeEraserCommandExecuted" />
        <CommandBinding Command="{x:Static self:InkCanvasControls.PointEraserCommand}" CanExecute="ToolCommandCanExecute" Executed="PointEraserCommandExecuted" />
        <CommandBinding Command="{x:Static self:InkCanvasControls.HighlighterCommand}" CanExecute="ToolCommandCanExecute" Executed="HighlighterCommandExecuted" />
        <CommandBinding Command="{x:Static self:InkCanvasControls.LassoCommand}" CanExecute="ToolCommandCanExecute" Executed="LassoCommandExecuted"/>
        <CommandBinding Command="{x:Static self:InkCanvasControls.ClearCommand}" CanExecute="ToolCommandCanExecute"  Executed="ClearCommand_Executed"/>
        <CommandBinding Command="{x:Static self:InkCanvasControls.UndoCommand}" CanExecute="UndoCommandCanExecute"  Executed="UndoCommand_Executed"/>
        <CommandBinding Command="{x:Static self:InkCanvasControls.RedoCommand}" CanExecute="RedoCommandCanExecute"  Executed="RedoCommand_Executed"/>
    </UserControl.CommandBindings>

    <Grid>
        <ToolBar Margin="0,10,-112,0" Name="toolBar" FocusManager.IsFocusScope="False">
            <!-- Drawing tool -->
            <RadioButton x:Name="Pen" Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                Command="{x:Static self:InkCanvasControls.PenCommand}" BorderBrush="Black" IsChecked="True" ToolTip="Draw with pen">
                <Grid Margin="2,2,0,0" Height="34" Width="60">
                    <Path Stroke="Blue" Data="M7,7 L7,23"/>
                    <Path Stroke="Blue" Data="M7,7 L47,7"/>
                </Grid>
            </RadioButton>
            <!-- Stroke erase tool -->
            <RadioButton x:Name="StrokeEraser" Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                         Command="{x:Static self:InkCanvasControls.StrokeEraserCommand}" BorderBrush="Black" ToolTip="Erase stroke by stroke">
                <Grid Margin="2,2,0,0" Height="34" Width="60">
                    <Path Stroke="Blue" Data="M7,7 L7,23"/>
                    <Path Stroke="Blue" Data="M7,7 L47,7"/>
                    <Path Stroke="Red" Data="M28,3 L38,10" StrokeThickness="2"/>
                    <Path Stroke="Red" Data="M38,3 L28,10" StrokeThickness="2"/>
                </Grid>
            </RadioButton>
            <!-- Point erase tool -->
            <RadioButton x:Name="PointEraser" Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                         Command="{x:Static self:InkCanvasControls.PointEraserCommand}" BorderBrush="Black" ToolTip="Erase point by point">
                <Grid Margin="2,2,0,0" Height="34" Width="60">
                    <Path Stroke="Blue" Data="M7,7 L7,23"/>
                    <Path Stroke="Blue" Data="M7,7 L47,7" StrokeDashArray="4.0"/>
                    <Path Stroke="Red" Data="M28,3 L38,10" StrokeThickness="2"/>
                    <Path Stroke="Red" Data="M38,3 L28,10" StrokeThickness="2"/>
                </Grid>
            </RadioButton>
            <!-- Highlight tool -->
            <RadioButton x:Name="Highlighter" Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                         Command="{x:Static self:InkCanvasControls.HighlighterCommand}" BorderBrush="Black" ToolTip="Highlight">
                <Grid Margin="2,2,0,0" Height="34" Width="60">
                    <Path Stroke="Yellow" StrokeThickness="10" Data="M12,7 L40,7"/>
                    <Path Stroke="Blue" Data="M7,7 L7,23"/>
                    <Path Stroke="Blue" Data="M7,7 L47,7"/>
                </Grid>
            </RadioButton>
            <!-- Stroke selection tool -->
            <RadioButton x:Name="Lasso" Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                         Command="{x:Static self:InkCanvasControls.LassoCommand}" BorderBrush="Black" ToolTip="Select strokes">
                <Grid Margin="2,2,0,0" Height="34" Width="60">

                    <Path Stroke="Blue" Data="M7,7 L7,23"/>
                    <Path Stroke="Blue" Data="M7,7 L47,7"/>
                    
                    <Path Fill="LightGray" Data="M1,1 L1,8 L8,8 L8,1 Z"/>
                    <Path Fill="LightGray" Data="M26,1 L26,8 L34,8 L34,1 Z"/>
                    <Path Stroke="DarkGray" Data="M8,4 L26,4" StrokeDashArray="2.0"/>
                    <Path Fill="LightGray" Data="M51,1 L51,8 L58,8 L58,1 Z"/>
                    <Path Stroke="DarkGray" Data="M26,4 L50,4" StrokeDashArray="2.0"/>
                    
                    <Path Fill="LightGray" Data="M1,26 L1,34 L8,34 L8,26 Z"/>
                    <Path Stroke="DarkGray" Data="M4,8 L4,26" StrokeDashArray="2.0"/>

                    <Path Fill="LightGray" Data="M26,26 L26,34 L34,34 L34,26 Z"/>
                    <Path Stroke="DarkGray" Data="M8,30 L26,30" StrokeDashArray="2.0"/>
                    <Path Fill="LightGray" Data="M51,26 L51,34 L58,34 L58,26 Z"/>
                    <Path Stroke="DarkGray" Data="M26,30 L50,30" StrokeDashArray="2.0"/>

                    <Path Stroke="DarkGray" Data="M54,8 L54,30" StrokeDashArray="2.0"/>

                </Grid>
            </RadioButton>
            <!-- Delete selected (or all) strokes button -->
            <Button  Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                     Command="{x:Static self:InkCanvasControls.ClearCommand}" BorderBrush="Black" ToolTip="Clear strokes">
                <Grid Margin="2,2,0,0" Height="34" Width="34">
                    <Path Stroke="Red" Data="M7,7 L27,27" StrokeThickness="2"/>
                    <Path Stroke="Red" Data="M27,7 L7,27" StrokeThickness="2"/>
                </Grid>
            </Button>
            <!-- Undo button -->
            <Button Visibility="{Binding UndoRedoSupport, Converter={StaticResource boolToVis}}"
                    Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                    Command="{x:Static self:InkCanvasControls.UndoCommand}" BorderBrush="Black"
                    Style="{StaticResource DisabledButton}" ToolTip="Undo" ToolTipService.ShowOnDisabled="True">
                <Grid Margin="2,2,0,0" Height="34" Width="34">
                    <Path Stroke="Blue" Data="M27,27 L27,9" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M27,9 L9,9" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M9,9 L14,4" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M9,9 L14,14" StrokeThickness="2"/>
                </Grid>
            </Button>
            <!-- Redo button -->
            <Button Visibility="{Binding UndoRedoSupport, Converter={StaticResource boolToVis}}"
                    Width="{Binding BarWidth, Converter={StaticResource ProportionOfWidth}}"
                    Command="{x:Static self:InkCanvasControls.RedoCommand}" BorderBrush="Black"
                    Style="{StaticResource DisabledButton}" ToolTip="Redo" ToolTipService.ShowOnDisabled="True">
                <Grid Margin="2,2,0,0" Height="34" Width="34">
                    <Path Stroke="Blue" Data="M9,9 L27,9" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M9,9 L9,27" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M29,9 L24,4" StrokeThickness="2"/>
                    <Path Stroke="Blue" Data="M29,9 L24,14" StrokeThickness="2"/>
                </Grid>
            </Button>

        </ToolBar>
    </Grid>
</UserControl>